/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgMallItem
    {
        private readonly Dictionary<int, CfgMallItem> _dataMap;
        private readonly List<CfgMallItem> _dataList;

        /// <summary>
        /// 按MallType作为key的Id列表
        /// </summary>
        public IReadOnlyDictionary<int, IReadOnlyList<int>> MallItemMap { get; private set; }

        public TbCfgMallItem(ByteBuf _buf)
        {
            //first read common data
            _TbCommonMallItem _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonMallItem(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgMallItem>(size * 3 / 2);
            _dataList = new List<CfgMallItem>(size);

            for (int i = 0; i < size; i++)
            {
                CfgMallItem _v;
                _v = CfgMallItem.DeserializeCfgMallItem(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 
            { int __n0 = _buf.ReadSize(); var __f0 = new Dictionary<int, IReadOnlyList<int>> (__n0 * 3 / 2); MallItemMap = __f0 ; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ) { int __k0; __k0 = _buf.ReadInt(); IReadOnlyList<int> __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0.Add(__k0, __v0); } }

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgMallItem> DataMap => _dataMap;
        public IReadOnlyList<CfgMallItem> DataList => _dataList;

        public CfgMallItem Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgMallItem] config not found,id:" + key.ToString());

            return null;
        }

        public CfgMallItem GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "mallitem";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgMallItem LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgMallItem(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgMallItem
    {
        private CfgMallItem(ByteBuf _buf, _TbCommonMallItem _commonData)
        {
            Id = _buf.ReadInt();
            MallType = _buf.ReadInt();
            Sort = _buf.ReadInt();
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            Desc = TableCenter.GetI18NText(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; Channels = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; InvisibleChannels = _commonData._field1[dataIndex]; }
            GoodsType = (MallGoodsType)(_buf.ReadInt());
            ShowItem = (MallShowItemType)(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; Item = _commonData._field2[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; ItemNum = _commonData._field3[dataIndex]; }
            SingleBuyLimits = _buf.ReadInt();
            SellType = (MallSellType)(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; Price = _commonData._field4[dataIndex]; }
            PayPoint = _buf.ReadInt();
            Discount = _buf.ReadInt();
            Tag = (MallItemTag)(_buf.ReadInt());
            LimitType = (MallLimitBuyCountType)(_buf.ReadInt());
            LimitTimes = _buf.ReadInt();
            ShowConditionId = _buf.ReadInt();
            ConditionId = _buf.ReadInt();
            TimeLimitType = (MallTimeLimitType)(_buf.ReadInt());
            { int dataIndex = _buf.ReadInt() - 1; TimeLimitOpen = _commonData._field5[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; TimeLimitEnd = _commonData._field6[dataIndex]; }
            SalesTime = _buf.ReadInt();
            EffectId = _buf.ReadInt();
            SoundId = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; EffectShow = _commonData._field7[dataIndex]; }
            Duration = _buf.ReadFloat();
            SoulDressID = _buf.ReadInt();
            BuyLimitShow = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; BG = _commonData._field8[dataIndex]; }
            RandomGroup = _buf.ReadInt();
            Weight = _buf.ReadInt();
            Amount = _buf.ReadFloat();
            GetPaypoint = _buf.ReadInt();
            BonusPaypoint = _buf.ReadInt();

            PostInit();
        }

        internal static CfgMallItem DeserializeCfgMallItem(ByteBuf _buf, _TbCommonMallItem _commonData)
        {
            return new CfgMallItem(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 所属商城
        /// </summary>
        public int MallType { get; private set; }
        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; private set; }
        /// <summary>
        /// 商品名字
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 商品描述
        /// </summary>
        public string Desc { get; private set; }
        /// <summary>
        /// 渠道限定商品
        /// </summary>
        public IReadOnlyList<string> Channels { get; private set; }
        /// <summary>
        /// 限定渠道不可见（填写后该渠道不可见该商品）
        /// </summary>
        public IReadOnlyList<string> InvisibleChannels { get; private set; }
        /// <summary>
        /// 商品界面类型 0-无道具 1-道具 2-购买界面自动读取道具列表
        /// </summary>
        public MallGoodsType GoodsType { get; private set; }
        /// <summary>
        /// 购买界面展示道具 0-无道具 1-单道具 2-多道具 3-家具主题
        /// </summary>
        public MallShowItemType ShowItem { get; private set; }
        /// <summary>
        /// 道具
        /// </summary>
        public IReadOnlyList<int> Item { get; private set; }
        /// <summary>
        /// 数量
        /// </summary>
        public IReadOnlyList<int> ItemNum { get; private set; }
        /// <summary>
        /// 单次购买数量限制（直充必须为1）
        /// </summary>
        public int SingleBuyLimits { get; private set; }
        /// <summary>
        /// 出售类型（0-免费 1-道具购买 2-付费货币购买 3-充值购买）
        /// </summary>
        public MallSellType SellType { get; private set; }
        /// <summary>
        /// 道具出售价格(selltype=1时生效）
        /// </summary>
        public IReadOnlyList<int> Price { get; private set; }
        /// <summary>
        /// 付费货币价格(selltype=2时生效)
        /// </summary>
        public int PayPoint { get; private set; }
        /// <summary>
        /// 原价
        /// </summary>
        public int Discount { get; private set; }
        /// <summary>
        /// 标签类型 1-折扣 2-限时 3-新品 4-畅销
        /// </summary>
        public MallItemTag Tag { get; private set; }
        /// <summary>
        /// 限购类型 0-不限购 1-每日 2-终生 3-每周 4-每月
        /// </summary>
        public MallLimitBuyCountType LimitType { get; private set; }
        /// <summary>
        /// 限购次数
        /// </summary>
        public int LimitTimes { get; private set; }
        /// <summary>
        /// 显示条件
        /// </summary>
        public int ShowConditionId { get; private set; }
        /// <summary>
        /// 购买条件
        /// </summary>
        public int ConditionId { get; private set; }
        /// <summary>
        /// 限时模式 1-时间、2-售卖时间
        /// </summary>
        public MallTimeLimitType TimeLimitType { get; private set; }
        /// <summary>
        /// 开启时间
        /// </summary>
        public string TimeLimitOpen { get; private set; }
        /// <summary>
        /// 结束时间
        /// </summary>
        public string TimeLimitEnd { get; private set; }
        /// <summary>
        /// 售卖时间（秒，对应类型2）
        /// </summary>
        public int SalesTime { get; private set; }
        /// <summary>
        /// 特效ID
        /// </summary>
        public int EffectId { get; private set; }
        /// <summary>
        /// 声音ID
        /// </summary>
        public int SoundId { get; private set; }
        /// <summary>
        /// 特效展示预设
        /// </summary>
        public string EffectShow { get; private set; }
        /// <summary>
        /// 展示持续时间
        /// </summary>
        public float Duration { get; private set; }
        /// <summary>
        /// 时装ID
        /// </summary>
        public int SoulDressID { get; private set; }
        /// <summary>
        /// 每日购买次数限制（纯客户端使用）
        /// </summary>
        public int BuyLimitShow { get; private set; }
        /// <summary>
        /// 背景资源/充值与时装使用
        /// </summary>
        public string BG { get; private set; }
        /// <summary>
        /// 随机商品组
        /// </summary>
        public int RandomGroup { get; private set; }
        /// <summary>
        /// 不为0时依据权重从同组中随机一个商品
        /// </summary>
        public int Weight { get; private set; }
        /// <summary>
        /// 付费金额
        /// </summary>
        public float Amount { get; private set; }
        /// <summary>
        /// 获得的付费货币
        /// </summary>
        public int GetPaypoint { get; private set; }
        /// <summary>
        /// 首充奖励付费货币
        /// </summary>
        public int BonusPaypoint { get; private set; }

        /// <summary>
        /// BG资源全路径
        /// </summary>
        public string BG_fullPath => $"Res/05_Images/Texture/UIMallRes/{BG}";

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonMallItem
    {

        internal IReadOnlyList<IReadOnlyList<string>> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<string>> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field2 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field3 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field4 { get; private set; }
        internal IReadOnlyList<string> _field5 { get; private set; }
        internal IReadOnlyList<string> _field6 { get; private set; }
        internal IReadOnlyList<string> _field7 { get; private set; }
        internal IReadOnlyList<string> _field8 { get; private set; }
        internal _TbCommonMallItem(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0][]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new string[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ string __v1; __v1 = _buf.ReadString(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new string[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ string __v1; __v1 = _buf.ReadString(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field5 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field6 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field7 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field8 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
